<?php
include "geofence.php";
$username = "lee";
$pass = "password";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $pass) 
  or die("Unable to connect to MySQL");
//echo "Connected to MySQL\n";
$selected = mysql_select_db("mywai",$dbhandle) 
  or die("Could not select mywai");
//echo "Connected!!\n";
function makefence($x, $y, $phi)
{
$dist = 5;
$flipIt = 180;
$rtAngle = 90;
$phiA = $phi + $flipIt;
$phiB = $phi + 90 + $flipIt;
$xA = number_format($x + ($dist * cos(deg2rad($phiA))), 1);
$yA = number_format($y + ($dist * sin(deg2rad($phiA))), 1);

$xB = number_format($x + ($dist * cos(deg2rad($phiB))), 1);
$yB = number_format($y + ($dist * sin(deg2rad($phiB))), 1);
$points = array($xA.','.$yA, $x.','.$y, $xB.','.$yB);
echo "Fence: [".$xA.",".$yA."] [".$x.",".$y."] [".$xB.",".$yB."]\n";
$result = mysql_query("SELECT Name, Latlng FROM locations")
	or die("Could not test database?");
$posLocs = array();
$tmpX_Y = array();
while ($row = mysql_fetch_array($result)) {
	$tmpX_Y = explode(",", $row['Latlng']);
	$tmpX = $tmpX_Y[0];
	$tmpY = $tmpX_Y[1];
   if(checkDb($tmpX, $tmpY, $points)){
		array_push($posLocs, array($row['Name'], $tmpX ,$tmpY));
   }
}
return $posLocs;
}

?>
